package com.atguigu.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class SentinelController {
	
	@GetMapping("/testa")
	public String getA(){
		log.info("method--A");
		return "method--A";
	}
	
	@GetMapping("/testb")
	public String getB(){
		return "method--B";
	}
	
	@GetMapping("/testc")
	public String getC(){
		Integer sleeptime = 1;
		try {
			TimeUnit.SECONDS.sleep(sleeptime);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		log.info("getC");
		return "method--C";
	}
	
	@GetMapping("/testHotKey")
	@SentinelResource(value = "testHotKey",blockHandler = "dealTestHotKey")
	public String testHotKey(@RequestParam(value = "p1",required = false) String p1,
	                         @RequestParam(value = "p2",required = false) String p2){
		return "****************testHotKey";
	}
	
	public String dealTestHotKey(String p1, String p2, BlockException e){
		return "****************deal_testHotKey……/(ㄒoㄒ)/~~";
		
	}
}
